package com.usian.controller;

import com.usian.pojo.TbUser;
import com.usian.service.SSOService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author chen
 * @date 2021/1/21 - 20:07 - 星期四
 * @project usian_parent
 * @package com.usian.controller
 * @by GGbomd猪猪侠
 */
@RestController
public class SSOController {

    @Autowired
    private SSOService SSOService;

    /**
     * 对用户的注册信息(用户名与电话号码)做数据校验
     * @param checkValue 用户名 和手机号
     * @param checkFlag
     * @return
     */
    @RequestMapping("/checkUserInfo/{checkValue}/{checkFlag}")
    public boolean checkUserInfo(@PathVariable String checkValue,@PathVariable Integer checkFlag){
        return SSOService.checkUserInfo(checkValue,checkFlag);
    }

    /**
     * 用户注册 相当于添加返回一条数据
     * @param tbUser
     * @return
     */
    @RequestMapping("/userRegister")
    public Integer userRegister(@RequestBody TbUser tbUser){
        return SSOService.userRegister(tbUser);
    }

    /**
     * u用户登录
     * @param username
     * @param password
     * @return
     */
    @RequestMapping("/userLogin")
    public Map userLogin(@RequestParam String username,@RequestParam String password){
        return SSOService.userLogin(username,password);
    }

    /**
     * 查询用户登录是否已经过期
     * @param token
     * @return
     */
    @RequestMapping("/getUserByToken/{token}")
    public TbUser getUserByToken (@PathVariable String token){
        return SSOService.getUserByToken(token);
    }

    /**
     * 退出登录
     * @param token
     * @return
     */
    @RequestMapping("/logOut")
    public Boolean logOut(@RequestParam String token){
        return SSOService.logOut(token);
    }
}
